Intro

This function is written with chromosome maps in mind but generalized for visualizing much more. All that is required is a data frame of segmants with columns called band, start, end.

In the future, I plan to keep it as generalized as possible, maximizing its flexibility and application in various types of analyses. Feel free to suggest ideas, report bugs, or contribute!

Source

source("bands.R")

Human gene locations

chromosomes <- c(paste("chr", 1:21, sep=""), "chrX", "chrY", "chrM")
df <- read.table('data/df.txt', sep="\t", header=TRUE, stringsAsFactors=FALSE)

Default plot

df.1 <- df[sample(1:nrow(df), 2500, replace=F),]
head(df.1)
       band     start       end      name
31523 chr17  36404825  36404932   TBC1D3F
5305   chr2 172315286 172323737   ZNF804A
30697 chr16  87129856  87133107   MIR6504
32633 chr18    894434    907680     SIRT7
28916 chr15  66278497  66293357    CIAO2A
26470 chr13  94574050  94596257 LINC01309
draw.bands(df.1, chromosomes, labels=F)

Add colors to highlight regions of interest

df.2 <- df.1
df.2$color <- ifelse(sample(c(T, T, T, F), 2500, replace=T), "grey", "firebrick")
head(df.2)
       band     start       end      name     color
31523 chr17  36404825  36404932   TBC1D3F      grey
5305   chr2 172315286 172323737   ZNF804A      grey
30697 chr16  87129856  87133107   MIR6504 firebrick
32633 chr18    894434    907680     SIRT7 firebrick
28916 chr15  66278497  66293357    CIAO2A      grey
26470 chr13  94574050  94596257 LINC01309      grey
draw.bands(df.2, chromosomes, labels=F)

Add names for hover info

df.3 <- head(df.2, 500)
head(df.3)
       band     start       end      name     color
31523 chr17  36404825  36404932   TBC1D3F      grey
5305   chr2 172315286 172323737   ZNF804A      grey
30697 chr16  87129856  87133107   MIR6504 firebrick
32633 chr18    894434    907680     SIRT7 firebrick
28916 chr15  66278497  66293357    CIAO2A      grey
26470 chr13  94574050  94596257 LINC01309      grey
draw.bands(df.3, chromosomes, labels=T)